package com.chinasoft.app.service.impl;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import com.chinasoft.app.dao.MessageDao;
import com.chinasoft.app.domain.Customer;
import com.chinasoft.app.domain.Messagebox;
import com.chinasoft.app.service.MessageService;
import com.chinasoft.app.vo.CustomerPage;
import com.chinasoft.app.vo.MessagePage;

@Transactional
public class MessageServiceImpl implements MessageService{
	private MessageDao messagedao;

	public void setMessagedao(MessageDao messagedao) {
		this.messagedao = messagedao;
	}

	@Override
	public void MessAdd(Messagebox messagebox) {
		messagedao.MessAdd(messagebox);
		
	}

	@Override
	public void MessDelete(int messid) {
		messagedao.MessDelete(messid);
		
	}


	@Override
	public MessagePage MessSearchByUser(String username, int currentpage,
			int pagesize) {
		MessagePage messagepage=new MessagePage();
		List<Messagebox> messagelist=messagedao.MessSearchByUser(username, currentpage, pagesize);
		messagepage.setCurrentpage(currentpage);
		messagepage.setPagesize(pagesize);
		messagepage.setMessagelist(messagelist);
		int totalcount=messagedao.findtotalMessCount(username);
		messagepage.setTotalcount(totalcount);
		messagepage.setTotalpage(totalcount % pagesize==0?totalcount/pagesize:totalcount/pagesize+1);
		return messagepage;
	}

	@Override
	public Messagebox findMessById(int messid) {
		Messagebox messagebox=messagedao.findMessById(messid);
		return messagebox;
	}

	@Override
	public void MessUpdate(Messagebox messagebox) {
		messagedao.MessUpdate(messagebox);
		
	}

}
